package org.fund.task;

import org.fund.base_service.service.IncomeRecordService;
import org.fund.base_service.service.impl.TempFundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * @Author Moro
 * @Date 2022/3/23 21:42
 * @title ScheduledTask
 */
@Component
public class ScheduledTask {

    @Autowired
    private IncomeRecordService recordService;
    @Autowired
    private TempFundService fundService;


    /**
     * 周一到周五的晚上10点整开始执行
     * 获取当日净值
     */
    @Async("executor")
    @Scheduled(cron = "0 0 22 ? * MON-FRI")
    public void  executeInsertCurrentJZ(){
        fundService.batchInsert();
    }
    @Async("executor")
    @Scheduled(cron = "0 10 22 ? * MON-FRI")
    public void  executeCalculateIncome(){
        recordService.batchInsert(recordService.calculateIncome());
    }


    /**
     * 周二到周六凌晨1点删除前天的净值数据
     */
    @Async("executor")
    @Scheduled(cron = "0 0 1 ? * TUE-FRI")
    public void  executeDeleteJZ(){
        fundService.batchDelete();
    }
}
